﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;

namespace Besture.UI.Admin.Hotels
{
    public partial class TrafficSet : BasePage
    {
        #region 属性
        /// <summary>
        /// 酒店ID
        /// </summary>
        private string _hotelsId = StringHelper.Query("hotelsId");
        #endregion

        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            hfID.Value = _hotelsId;
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {

        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new TrafficDac();
            var model = dac.GetModel(id);

            txtLocation.Text = model.Location.ToString();
            txtGettingThere.Text = model.GettingThere.ToString();
            txtSortID.SortValue = model.SortID != 0 ? model.SortID : 0;



        }
        #endregion

        #region 保存

        protected void BtnSubmitClick(object sender, EventArgs eventArgs)
        {
            var dac = new TrafficDac();
            TrafficModel model = null;
            var baseDac = new BaseDac<TrafficModel>();
            //添加
            if (!EditPage)
            {
                model = new TrafficModel();
                model.Location = txtLocation.Text.Trim();
                model.GettingThere = txtGettingThere.Text.Trim();
                model.SortID = txtSortID.SortValue != 0 ? txtSortID.SortValue : 0;
                model.HotelsID = String.IsNullOrEmpty(_hotelsId) ? 0 : Convert.ToInt32(_hotelsId);

                //加载添加基本数据
                baseDac.LoadAddBaseModel(model);

                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(ID);
                model.Location = txtLocation.Text.Trim();
                model.GettingThere = txtGettingThere.Text.Trim();
                model.SortID = txtSortID.SortValue != 0 ? txtSortID.SortValue : 0;
                model.HotelsID = String.IsNullOrEmpty(_hotelsId) ? 0 : Convert.ToInt32(_hotelsId);

                //加载修改基本数据
                baseDac.LoadUpdateBaseModel(model);

                dac.Update(model);
            }

            ClientScript.RegisterStartupScript(GetType(), "", "parent.closeTrafficTree();", true);
            //FunHelper.Alert("保存成功", ListUrl());
        }
        #endregion
    }
}